package bukutelepon.tabel;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class tabelmodeldata extends AbstractTableModel
{
    private List<data> list = new ArrayList<data>();
    public void add(data data)
    {
        list.add(data);
        fireTableRowsInserted(getRowCount(), getColumnCount());
    }

    public void delete(int i, int row)
    {
        list.remove(i);
        fireTableRowsDeleted(i, row);
    }

    public data get(int row)
    {
        return (data) list.get(row);
    }

    public int getRowCount()
    {
        return list.size();
    }

    public int getColumnCount()
    {
        return 3;
    }

    public Object getValueAt(int rowIndex, int columnIndex)
    {
        switch(columnIndex)
        {
            case 0 : return list.get(rowIndex).getnomer();
            case 1 : return list.get(rowIndex).getNama();
            case 2 : return list.get(rowIndex).getAlamat();
            default: return null;
        }
    }

    @Override
    public String getColumnName(int column)
    {
        switch(column)
        {
            case 0 : return "Nomer Telepon";
            case 1 : return "NAMA";
            case 2 : return "ALAMAT";
            default: return null;
        }
    }
}